package io.adrainty.algorithm.leetcode.lcr;

/**
 * LCR 005. 最大单词长度乘积
 * @link <a href="https://leetcode.cn/problems/aseY1I/">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @since 2024/9/1 上午12:38
 */
public class LCR005 {

    public int maxProduct(String[] words) {
        // 代替hash表
        boolean[][] flags = new boolean[words.length][26];
        for (int i = 0; i < words.length; i++) {
            for (char c : words[i].toCharArray()) {
                flags[i][c - 'a'] = true;
            }
        }

        int res = 0;
        for (int i = 0; i < words.length; i++) {
            for (int j = i + 1; j < words.length; j++) {
                int count = 0;
                for (; count < 26; count++) {
                    if (flags[i][count] && flags[j][count]) {
                        break;
                    }
                }

                if (count == 26) {
                    res = Math.max(res, words[i].length() * words[j].length());
                }
            }
        }
        return res;
    }

}
